
#define SIZE_REG    8

# These GP registers to be saved don't include gp
# and tp, because they are not caller-saved or
# callee-saved. These two registers are often used
# for special purpose. For example, in RVOS, 'tp'
# (aka "thread pointer") is used to store hartid,
# which is a global value and would not be changed
# during context-switch.

.macro SAVE_REG base
    REG_S ra,   0*SIZE_REG(\base)
    REG_S sp,   1*SIZE_REG(\base)
    REG_S t0,   4*SIZE_REG(\base)
    REG_S t1,   5*SIZE_REG(\base)
    REG_S t2,   6*SIZE_REG(\base)
    REG_S s0,   7*SIZE_REG(\base)
    REG_S s1,   8*SIZE_REG(\base)
    REG_S a0,   9*SIZE_REG(\base)
    REG_S a1,  10*SIZE_REG(\base)
    REG_S a2,  11*SIZE_REG(\base)
    REG_S a3,  12*SIZE_REG(\base)
    REG_S a4,  13*SIZE_REG(\base)
    REG_S a5,  14*SIZE_REG(\base)
    REG_S a6,  15*SIZE_REG(\base)
    REG_S a7,  16*SIZE_REG(\base)
    REG_S s2,  17*SIZE_REG(\base)
    REG_S s3,  18*SIZE_REG(\base)
    REG_S s4,  19*SIZE_REG(\base)
    REG_S s5,  20*SIZE_REG(\base)
    REG_S s6,  21*SIZE_REG(\base)
    REG_S s7,  22*SIZE_REG(\base)
    REG_S s8,  23*SIZE_REG(\base)
    REG_S s9,  24*SIZE_REG(\base)
    REG_S s10, 25*SIZE_REG(\base)
    REG_S s11, 26*SIZE_REG(\base)
    REG_S t3,  27*SIZE_REG(\base)
    REG_S t4,  28*SIZE_REG(\base)
    REG_S t5,  29*SIZE_REG(\base)
    # we don't save t6 here, due to we have used
    # it as base, we have to save t6 in an extra step
    # outside of reg_save
.endm


.macro RESTORE_REG base
    REG_L ra,   0*SIZE_REG(\base)
    REG_L sp,   1*SIZE_REG(\base)
    REG_L t0,   4*SIZE_REG(\base)
    REG_L t1,   5*SIZE_REG(\base)
    REG_L t2,   6*SIZE_REG(\base)
    REG_L s0,   7*SIZE_REG(\base)
    REG_L s1,   8*SIZE_REG(\base)
    REG_L a0,   9*SIZE_REG(\base)
    REG_L a1,  10*SIZE_REG(\base)
    REG_L a2,  11*SIZE_REG(\base)
    REG_L a3,  12*SIZE_REG(\base)
    REG_L a4,  13*SIZE_REG(\base)
    REG_L a5,  14*SIZE_REG(\base)
    REG_L a6,  15*SIZE_REG(\base)
    REG_L a7,  16*SIZE_REG(\base)
    REG_L s2,  17*SIZE_REG(\base)
    REG_L s3,  18*SIZE_REG(\base)
    REG_L s4,  19*SIZE_REG(\base)
    REG_L s5,  20*SIZE_REG(\base)
    REG_L s6,  21*SIZE_REG(\base)
    REG_L s7,  22*SIZE_REG(\base)
    REG_L s8,  23*SIZE_REG(\base)
    REG_L s9,  24*SIZE_REG(\base)
    REG_L s10, 25*SIZE_REG(\base)
    REG_L s11, 26*SIZE_REG(\base)
    REG_L t3,  27*SIZE_REG(\base)
    REG_L t4,  28*SIZE_REG(\base)
    REG_L t5,  29*SIZE_REG(\base)
	REG_L t6,  29*SIZE_REG(\base)
.endm


